package cn.jboa.service.impl;

import cn.jboa.common.Constants;
import cn.jboa.entity.SysEmployee;
import org.springframework.stereotype.Service;

import java.util.*;
@Service("claimVoucherServiceStuff")
public class ClaimVoucherServiceImplStuff extends BaseClaimVoucherServiceImpl{

    private static Map<String, String> statusMap;
    static {
        statusMap = new LinkedHashMap<>();
        statusMap.put(Constants.CLAIMVOUCHER_CREATED, "新创建");
        statusMap.put(Constants.CLAIMVOUCHER_SUBMITTED, "已提交");
        statusMap.put(Constants.CLAIMVOUCHER_APPROVING, "待审批");
        statusMap.put(Constants.CLAIMVOUCHER_BACK, "已打回");
        statusMap.put(Constants.CLAIMVOUCHER_APPROVED, "已审批");
        statusMap.put(Constants.CLAIMVOUCHER_PAID, "已付款");
        statusMap.put(Constants.CLAIMVOUCHER_TERMINATED, "已终止");
    }
    @Override
    protected void buildBaseHql(SysEmployee emp, String status, Date startDate, Date endDate, StringBuilder hqlBuilder, List<Object> values) {

        hqlBuilder.append("from BizClaimVoucher where creator.sn = ?");
        values.add(emp.getSn());

        if (status != null && status.length() != 0) {
            hqlBuilder.append(" and status = ?");
            values.add(status);
        }
        if (startDate != null) {
            hqlBuilder.append(" and createTime >= ?");// yyyy-MM-dd 00:00:00
            values.add(startDate);
        }
        if (endDate != null) {
            hqlBuilder.append(" and createTime < ?");// yyyy-MM-dd 00:00:00
            Calendar oneDayLater = Calendar.getInstance();
            oneDayLater.setTime(endDate);
            oneDayLater.add(Calendar.DAY_OF_MONTH, 1);
            values.add(oneDayLater.getTime());
        }

    }
    @Override
    protected void addOrders(String status, StringBuilder hqlBuilder) {
        if (status == null || status.length() == 0)
            hqlBuilder.append(" order by status, createTime desc");
        else
            hqlBuilder.append(" order by createTime desc");
    }
    @Override
    public Map<String, String> getStatusMap() {
        return statusMap;
    }
}
